<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>微信名称：<input type="text" name="wxName" />
							</li>
							<li>appId：<input type="text" name="appId" />
							</li>
							<li><a class="btn btn-primary btn-rounded btn-sm"
								onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm"
								onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()"
					shiro:hasPermission="system:role:add"> <i class="fa fa-plus"></i>
					新增
				</a> <a class="btn btn-primary btn-edit disabled"
					onclick="$.operate.edit()" shiro:hasPermission="system:role:edit">
					<i class="fa fa-edit"></i> 修改
				</a> <a class="btn btn-danger btn-del disabled"
					onclick="$.operate.removeAll()"
					shiro:hasPermission="system:role:remove"> <i
					class="fa fa-remove"></i> 删除
				</a>
			</div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<div th:include="include :: footer"></div>
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:wxCode:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:wxCode:remove')}]];
		
		var prefix = ctx + "system/wxCode/";
		
		/* 获取关注用户 */		
		function getConcernUser(appId,appSecret){
			$.ajax({
	    		cache : true,
	    		type : "POST",
	    		url : prefix + "/concernUsers",
	    		data : {
	    			"appId": appId,
	    			"appSecret": appSecret
	    		},
	    		async : false,
	    		error : function(request) {
	    			$.modal.alertError("系统错误");
	    		},
	    		success : function(data) {
	    			$.modal.msg("获取关注用户数据成功！", modal_status.SUCCESS);
	    		}
	    	});
		}

		/* 微信管理后台 */
		function codeManager(appId){
			$.open("");
		}

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        sortName: "createAt", // 排序字段
		        modalName: "微信号",
		        search: false,
		        showExport: false,
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'wxId',
		            visible: false
		        },
		        {
		            field: 'wxCode',
		            title: '微信号',
                    visible: false
		        },
		        {
		            field: 'wxName',
		            title: '微信名称'
		        },
		        {
		            field: 'appId',
		            title: 'appId'
		        },
		        {
		            field: 'appSecret',
		            title: 'appSecret',
		        },
                {
                    field: 'accessToken',
                    title: 'accessToken',
                    align: 'center',
                    formatter: function(value) {
                        if (value == null) {
                            return '<span class="badge badge-danger">无</span>';
                        } else {
                            return '<span class="badge badge-primary">有</span>';
                        }
                    }
                },
                {
                    field: 'errCode',
                    title: 'errCode',
                },
                {
                    field: 'errMsg',
                    title: 'errMsg',
                    formatter: function(value) {
                        if (value != null) {
                            return '<span class="label label-danger">'+value+'</span>';
                        }
                    }
                },
		        {
		            field: 'createAt',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
                    field: 'wxId',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.wxId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-danger btn-xs  ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.wxId + '\')"><i class="fa fa-remove"></i>删除</a> ');
		                return actions.join('');
		            }
		        },
                    {
                        title: '管理',
                        field: 'wxId',
                        align: 'center',
                        formatter: function(value,row) {
                            var actions = [];
                            actions.push('<a class="btn btn-info btn-xs " onclick="javascript:showSendMsg('+value+',\''+row.wxName+'\')" href="#" >消息群发</a> ');
                            actions.push('<a class="btn btn-info btn-xs " target="_blank" href="/wx/index?wxId='+value+'" >微信管理后台</a> ');

                            return actions.join('');
                        }
                    }

		        ]
		    };
		    $.table.init(options);
		});

        //消息群发
        function showSendMsg(id,name) {
            var url = ctx + 'system/wxTemplates/sendMsg?wxId='+id;
            createMenuItem(url, name + "消息群发");
        }
	</script>
</body>
</html>